/*
 * Copyright (c) 2013, Ivan Babushkin.
 */
package asntest;

import asngen.codec.*;
import asngen.generated.*;
import asngen.core.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        INTU8 unsigned = new INTU8(128);
        INTI8 signed = new INTI8(-128);
        ByteArrayOutputStream os = new ByteArrayOutputStream(100);

        System.out.println("unsigned: " + unsigned.getValue());
        System.out.println("signed: " + signed.getValue());

        Encoder encoder = new TestEncoder(os);
        encoder.encode(unsigned);
        encoder.encode(signed);

        byte[] buf = os.toByteArray();
        dump(buf);

        ByteArrayInputStream is = new ByteArrayInputStream(buf);
        Decoder decoder = new TestDecoder(is);
        INTU8 unsignedImage = new INTU8(decoder);
        INTI8 signedImage = new INTI8(decoder);

        System.out.println("unsignedImage: " + unsignedImage.getValue());
        System.out.println("signedImage: " + signedImage.getValue());
    }

    private static void dump(byte[] bytes) {
        for (byte i: bytes) {
            System.out.printf("0x%02x ", i);
        }
        System.out.println();
    }
}
